/**
 * 维修  整改  投诉的保养异常资料
 */
import React from 'react'
import { Table } from 'antd'
import './index.styl'
import TitleLine from 'components/common/titleLine'
import repairCn from 'columns/deviceRepair'
import { randomString } from 'utils/format'

// 状态
function MaintenanceError({ data }) {

  const statusStr = (key) => {
    switch (Number(key)) {
      case 1:
        return '未开始';
      case 2:
        return '进行中';
      case 3:
        return '待确认';
      case 4:
        return '已完成';
      case 5:
        return '不合格';
      case 6:
        return '超时完成';
      default:
        return '——';
    }
  }

  // 添加序号
  repairCn.maintenanceError[0].render = (t, r, i) => `${i+1}`
  // 任务执行时间
  repairCn.maintenanceError[2].render = (t) => <span>{t ? t : '——'}</span>
  // 状态
  repairCn.maintenanceError[3].render = (t, r) => <span>{statusStr(r.status)}</span>

  // 执行结果
  repairCn.maintenanceError[4].render = (t, r) => (
    <>
      <span>
        { Number(r.result) === 1 ? '成功' : null}
        { Number(r.result) === -1 ? '——' : null}
        { Number(r.result) === 0 ? `失败${r.failReason ? `：${r.failReason}` : ''}` : null}
      </span>
    </>
  )

  const { orderMaintainerror } = data ? data : { orderMaintainerror: [] }
  return (
    <div className='MaintenanceErrorBox'>
      <TitleLine title='保养异常资料' />
      <Table
        columns={repairCn.maintenanceError}
        dataSource={orderMaintainerror}
        pagination={false}
        bordered={true}
        className="self-table"
        rowKey={() => randomString()}
      />
    </div>
  )
}
export default MaintenanceError

